<!--
Filename: routelibrary.php

Primary Author: Tyler Mazaika
Coin 71 Group 1
Palo Alto Bicycle Club - Route Library

Constructs a table of all routes listed in "routelibrary.xml" with options to filter by 
ride category and hilliness.  Clicking on a ride leads to the full text of the ride in
it's original format.

-->

<div id="routeLibrary">

    <h3>Route Library</h3>
    <table cellpadding="0" cellspacing="0" border="0" class="" id="routeList">
        <thead>
            <tr>
                <th>Route Name <br />&nbsp;</th>
                <th>Category <br />
                    <select>
                        <option value="">All</option>
                        <option value="A">A</option>
                        <option value="B">B</option>
                        <option value="C">C</option>
                        <option value="D">D</option>
                        <option value="E">E</option>
                        <option value="F">F</option>
                    </select></th>
                <th>Hilliness <br />
                    <select>
                        <option value="">All</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                    </select></th>
                <th>Mileage <br />&nbsp;</th>
            </tr>
        </thead>
        <tbody>
            <?php

            // creates table based on XML route data

            $doc = new DOMDocument;
            $doc->load("routelibrary.xml");

            $routes = $doc->getElementsByTagName('route');

            $libArray = array();                        // store the array of routes

            foreach ( $routes as $route) {
                $libArray [] = array(                   // store each Route as an associative array in $libArray
                    'title' => $route->getElementsByTagName('title')->item( 0 )->nodeValue,
                    'category' => $route->getElementsByTagName('category')->item( 0 )->nodeValue,
                    'hilliness' => $route->getElementsByTagName('hilliness')->item( 0 )->nodeValue,
                    'mileage' => $route->getElementsByTagName('mileage')->item( 0 )->nodeValue
                );
            }
                
                // each route is made into a table row.
            foreach( $libArray as $i => $route ) {
                echo '<tr><td><a onclick="getRoutePage('.$i.')" href="javascript:void(0);">'.$route[ 'title' ].'</a></td><td>'.$route[ 'category' ] .'</td><td>'.$route[ 'hilliness' ] .'</td><td>'.$route[ 'mileage' ] .'</td></tr>';
            }
            ?>
        </tbody>
    </table>
</div>
